{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0631c124-d39c-4d1b-ac1d-f303025d6add",
   "metadata": {
    "libroCellType": "text"
   },
   "source": [
    "<p data-lake-id=\"u0cf9b974\" id=\"u0cf9b974\"><br></p>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c043615d-8739-49b1-925c-88d2b4c023ae",
   "metadata": {
    "execution": {
     "shell.execute_reply.end": "2023-12-13T09:05:19.247182Z",
     "shell.execute_reply.started": "2023-12-13T09:05:18.939630Z",
     "to_execute": "2023-12-13T09:05:18.876Z"
    }
   },
   "outputs": [],
   "source": [
    "# generate non-overlap \n",
    "import os\n",
    "import random\n",
    "from typing import DefaultDict\n",
    "from tqdm import tqdm\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from collections import defaultdict\n",
    "import json\n",
    "from random import sample\n",
    "\n",
    "def select_overlap_user(train_name,save_train_name,overlap_ratio):\n",
    "    data = pd.read_csv(train_name)\n",
    "    user_node = data['user_id'].tolist()\n",
    "    seq_d1 = data['seq_d1'].tolist()\n",
    "    seq_d2 = data['seq_d2'].tolist()\n",
    "    domain_id = data['domain_id'].tolist()\n",
    "    # ob_label = data['ob_label'].tolist()\n",
    "    user_node_overlap,seq_d1_overlap, seq_d2_overlap, domain_id_overlap  = [], [], [], []\n",
    "    user_node_nolap,seq_d1_nolap, seq_d2_nolap, domain_id_nolap, ob_label_nolap  = [], [], [], [], []\n",
    "    for i in range(len(user_node)):\n",
    "        seq1_tmp = json.loads(seq_d1[i])\n",
    "        seq2_tmp = json.loads(seq_d2[i])\n",
    "        if len(seq1_tmp)!=0 and len(seq2_tmp)!=0:\n",
    "            user_node_overlap.append(user_node[i])\n",
    "            seq_d1_overlap.append(seq1_tmp)\n",
    "            seq_d2_overlap.append(seq2_tmp)\n",
    "            domain_id_overlap.append(domain_id[i])\n",
    "        else :\n",
    "            user_node_nolap.append(user_node[i])\n",
    "            seq_d1_nolap.append(seq1_tmp)\n",
    "            seq_d2_nolap.append(seq2_tmp)\n",
    "            domain_id_nolap.append(domain_id[i])\n",
    "            # ob_label_nolap.append(ob_label[i])\n",
    "    dataframe = pd.DataFrame({'user_id':user_node_nolap,'seq_d1':seq_d1_nolap,'seq_d2':seq_d2_nolap,'domain_id':domain_id_nolap}) #, 'ob_label':ob_label_nolap})\n",
    "    dataframe.to_csv(save_train_name,index=False,sep=',')\n",
    "\n",
    "overlap_ratio = 0\n",
    "save_train_name = \"/ossfs/workspace/CDSR/amazon_dataset/phone_elec_test_nonoverlap.csv\"\n",
    "train_name = \"/ossfs/workspace/CDSR/amazon_dataset/phone_elec_test.csv\"\n",
    "select_overlap_user(train_name,save_train_name,overlap_ratio)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b2671a57-36ce-4daa-bc5f-0be17d2aaec5",
   "metadata": {
    "execution": {
     "shell.execute_reply.end": "2023-12-13T06:39:48.682424Z",
     "shell.execute_reply.started": "2023-12-13T06:39:48.667590Z",
     "to_execute": "2023-12-13T06:39:48.622Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3641\n"
     ]
    }
   ],
   "source": [
    "print(len(pd.read_csv(\"/ossfs/workspace/CDSR/amazon_dataset/cloth_sport_train25_nonoverlap.csv\")))"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
